package com.CTAtracker.android.XML;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;


public class InternetHeader {

	/**
	 * The result of the request
	 */
	private String _result = null;
	/**
	 * The date of the response
	 */
	private String _date; 
	/**
	 * The error code of the response
	 */
	private int _errorCode; 
	/**
	 * The error Message return by the API
	 */
	private String _errorMessage; 
	
	public InternetHeader(){
		_date = "";
		_errorCode = 0; 
		_errorMessage = "";
	}
	
	public InternetHeader(String date, int code, String message){
		_date = date; 
		_errorCode = code; 
		_errorMessage = message; 
	}

	/**
	 * Read the ETA from the API response
	 * @param parser the parser
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	public void readETA(XmlPullParser parser) throws XmlPullParserException, IOException {
		parser.require(XmlPullParser.START_TAG, _result, InternetData.TIME_STAMP);
        _date = APIXmlParser.readText(parser);
        parser.require(XmlPullParser.END_TAG, _result, InternetData.TIME_STAMP);
	}

	/**
	 * Read the error code from the API response
	 * @param parser the parser
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public void readCodeError(XmlPullParser parser) throws IOException, XmlPullParserException {
		parser.require(XmlPullParser.START_TAG, _result, InternetData.ERROR_CODE);
        _errorCode = APIXmlParser.readInt(parser);
        parser.require(XmlPullParser.END_TAG, _result, InternetData.ERROR_CODE);//return summary;
	}

	/**
	 * Read the error message from the API response
	 * @param parser the parser
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	public void readMessageError(XmlPullParser parser) throws XmlPullParserException, IOException {
		parser.require(XmlPullParser.START_TAG, _result, InternetData.ERROR_CODE);
        _errorMessage = APIXmlParser.readText(parser);
        parser.require(XmlPullParser.END_TAG, _result, InternetData.ERROR_CODE);
    }

	public String get_date() {
		return _date;
	}

	public void set_date(String _date) {
		this._date = _date;
	}

	public int get_errorCode() {
		return _errorCode;
	}

	public void set_errorCode(int _errorCode) {
		this._errorCode = _errorCode;
	}

	public String get_errorMessage() {
		return _errorMessage;
	}

	public void set_errorMessage(String _errorMessage) {
		this._errorMessage = _errorMessage;
	}

}